package com.sex.spring.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.sex.spring.model.User;
import com.sex.spring.service.UserService;


/**
 * 
 * @author Daven.Tsang
 *
 */
@Controller
@RequestMapping(value = "/user")
public class UserController {

	@Autowired
	private UserService userService;
	Map<String, Object> map = new HashMap<>();
	
	@RequestMapping(value = "/toRegister.do",method={RequestMethod.GET})
	public String toRegister(Model model) {
		
		return "user/register";
	}
	
	@RequestMapping(value = "/register.do")
	public String register(Model model,User rocerd) {
		try {
			userService.addUser(rocerd);
			map.put("code", 1);
			map.put("msg", "用户注册成功！！");
		} catch (Exception e) {
			map.put("code", 0);
			map.put("msg", "用户注册异常！！");
		}
		model.addAttribute("map", map);
		return "user/login";
	}
}
